package cn.stylefeng.guns.modular.pandian.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.pandian.entity.PandianChoupan;
import cn.stylefeng.guns.modular.pandian.model.params.PandianChoupanParam;
import cn.stylefeng.guns.modular.pandian.service.PandianChoupanService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 抽盘表控制器
 */
@Controller
@RequestMapping("/pandianChoupan")
public class PandianChoupanController extends BaseController {

    private String PREFIX = "/pandian/pandianChoupan";

    @Autowired
    private PandianChoupanService pandianChoupanService;

    @Autowired
    private UserService userService;

    @Autowired
    private BasicWarehouseService basicWarehouseService;

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
    	//查询可选择仓库
    	model.addAttribute("basicWarehouseList", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/pandianChoupan.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/pandianChoupan_add.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/pandianChoupan_edit.html";
    }

    /**
     * 新增接口
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(PandianChoupanParam pandianChoupanParam) {
        this.pandianChoupanService.add(pandianChoupanParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(PandianChoupanParam pandianChoupanParam) {
        this.pandianChoupanService.update(pandianChoupanParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(PandianChoupanParam pandianChoupanParam) {
        this.pandianChoupanService.delete(pandianChoupanParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(PandianChoupanParam pandianChoupanParam) {
        PandianChoupan detail = this.pandianChoupanService.getById(pandianChoupanParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(PandianChoupanParam pandianChoupanParam,String condition ) {
    	User user = userService.getcurrentUser();
    	pandianChoupanParam.setDeptId(user.getDeptId());
        return this.pandianChoupanService.findPageBySpec(pandianChoupanParam,condition,user.getOperateId());
    }

}


